package com.lee.lxl.idcard.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lee.lxl.idcard.Bean.ChatBean;
import com.lee.lxl.idcard.R;
import com.lee.lxl.idcard.tools.SPUtils;

import java.util.List;

/**
 * Created by lee-lxl on 2016/6/6.
 */
public class ChatAdapter extends BaseAdapter{

    private Context mContext;
    private LayoutInflater inflater;
    private List<ChatBean> mlist;

    public ChatAdapter(Context mContext,List<ChatBean> mlist){
        super();
        this.mContext = mContext;
        this.mlist =mlist;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.listview_chat,null);
            holder.tv_chat_mychat = (TextView) convertView.findViewById(R.id.tv_chat_mychat);
            holder.tv_chat_yours = (TextView) convertView.findViewById(R.id.tv_chat_yours);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(SPUtils.get(mContext,"chat","").equals("true")){
            holder.tv_chat_yours.setVisibility(View.GONE);
            Log.e("ChatAdapter", "tv_chat_yours  GONE");

            holder.tv_chat_mychat.setText(mlist.get(position).getMytext().toString());
            Log.e("ChatAdapter", "tv_chat_mychat   " + mlist.get(position).getMytext().toString());
        }else{
            holder.tv_chat_mychat.setVisibility(View.GONE);
            Log.e("ChatAdapter", "tv_chat_mychat  GONE");

            holder.tv_chat_yours.setText(mlist.get(position).getText().toString());
            Log.e("ChatAdapter", "tv_chat_yours   " + mlist.get(position).getText().toString());
        }
//        holder.tv_chat_mychat.setText(mlist.get(position).getMytext().toString());
//        Log.e("ChatAdapter  my", mlist.get(position).getMytext().toString());
//        holder.tv_chat_yours.setText(mlist.get(position).getText().toString());
//        Log.e("ChatAdapter  you", mlist.get(position).getText().toString());

        return convertView;
    }
}

class ViewHolder{
    TextView tv_chat_yours, tv_chat_mychat;
}